{% extends "../base.html" %}
{% block content %}

  <script language="javascript" type="text/javascript">

    function myClick(_num)
    {
      var frm = document.getElementById("fld_form");
      var act = frm.elements["action"];
      switch (_num) {
        case 1:  act.value = "insert"; break;
        case 2:  act.value = "update"; break;
        case 3:  act.value = "delete"; break;
        case 4:  act.value = "cancel"; break;
        default: act.value = "undef"; 
      }
      frm.Submit();
      return true;
    }

  </script>

  
  <div id="gmenu" class="menu"> <a href="/">{{ app_text }}</a> | <a href="/fuel/car">{{ car_text }}</a> </div> <br/>
  <div class="PageTitle">   {{ page_title }}   {% for r in cars %} | <a href="/fuel?car={{ r.pid }}"> {{ r.name }} </a> {% endfor %} </div>
  <div>                     {{ fuel_summary }} </div>
  <div class="PageStatus">  {{ fuel_status }}  </div>

  <form id="fld_form" action="/fuel" method="post">
    <input name="pid"    type="hidden" value="{{ cur.pid }}">
    <input name="action" type="hidden" value="none">
    <table class="fl1"><tbody>
      {% if edit_rec %} 
      <tr><td class="fl1"> ID:      </td><td class="fl2"> {{ cur.pid }} </td> </tr>
      {% endif %} 
      <tr><td class="fl1"> Дата:    </td><td class="fl2"> <input name="date"    size="10" type="text"   value="{{ cur.s_date }}" />  </td> </tr>
      <tr><td class="fl1"> Счетчик: </td><td class="fl2"> <input name="counter" size="10" type="number" value="{{ cur.counter }}" /> </td> </tr>
      <tr><td class="fl1"> Объём:   </td><td class="fl2"> <input name="volume"  size="10" type="text"   value="{{ cur.volume }}" />  </td> </tr>
      <tr><td class="fl1"> Цена:    </td><td class="fl2"> <input name="price"   size="10" type="number" value="{{ cur.iprice }}" />   </td> </tr>
    </tbody></table>
    {% if edit_rec %} 
      <input type="submit" class="LiteButton" id="update" value="Сохранить" onClick="myClick(2)" >
      <input type="submit" class="LiteButton" id="delete" value="Удалить"   onClick="myClick(3)" >
      <input type="submit" class="LiteButton" id="common" value="Отменить"  onClick="myClick(4)" >
    {% else %}
      <input type="submit" class="LiteButton" id="update" value="Добавить"  onClick="myClick(1)" >
    {% endif %}
  </form>

  {% if fuels.count %}
  <table class="work">
    <tbody><tr>
      <th class="work"> ID    </th>
      <th class="work"> Дата  </th>
      <th class="work"> Сч.   </th>
      <th class="work"> Об.   </th>
      <th class="work"> Цена  </th>
      <th class="work"> Сумма </th>
    </tr>
    {% for f in fuels %}
    <tr>
      <td class="pid">  <a href="/fuel?pid={{ f.pid }}"> {{ f.pid }} </a> </td>
      <td class="work"> {{ f.date.day|escape }}.{{ f.date.month|escape }}.{{ f.date.year|escape }} </td>
      <td class="work"> {{ f.counter }} </td>
      <td class="work"> {{ f.volume }}  </td>
      <td class="work"> {{ f.iprice }}  </td>
      <td class="work"> {{ f.summ }}    </td>
    </tr>
    {% endfor %}
  </tbody></table>
  {% endif %}

  <br/>Всего заправок: {{ fuels.count }}<br/>

{% endblock %}
